<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.gxgyl.com All rights reserved.

// +----------------------------------------------------------------------
// | Author: Liuyu
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\store\controller\shiyao;

use app\store\controller\Controller;
use app\store\model\shiyao\Company as CompanyModel;

/**
 * 申办方控制器
 * Class StoreUser
 * @package app\store\controller
 */
class Company extends Controller {


		/**
	 * 用户充值
	 * @param int $userId
	 * @param string $target
	 * @return array
	 */
	public function recharge(int $companyId, string $target) {
		// 用户详情
		$model = CompanyModel::detail($companyId);
		if ($model->recharge($target, $this->postForm())) {
			return $this->renderSuccess('操作成功');
		}
		return $this->renderError($model->getError() ?: '操作失败');
	}

public function detail(int $companyId) {

		$detail = CompanyModel::detail($companyId);
		return $this->renderSuccess(compact('detail'));
	}
	public function listAll() {
		$model = new CompanyModel;
		$list = $model->getListAll();
		return $this->renderSuccess(compact('list'));
	}

	/**
	 * 管理员列表
	 * @return array
	 * @throws \think\db\exception\DbException
	 */
	public function list() {
		$model = new CompanyModel;
		$list = $model->getList($this->request->param());
		return $this->renderSuccess(compact('list'));
	}

	/**
	 * 添加管理员
	 * @return array
	 */
	public function add() {
		// 新增记录
		$model = new CompanyModel;
		if ($model->add($this->postForm())) {
			return $this->renderSuccess('添加成功');
		}
		return $this->renderError($model->getError() ?: '添加失败');
	}

	/**
	 * 更新管理员
	 * @param int $companyId
	 * @return array
	 */
	public function edit(int $companyId) {
		// 管理员详情
		$model = CompanyModel::detail($companyId);
		// 更新记录
		if ($model->edit($this->postForm())) {
			return $this->renderSuccess('更新成功');
		}
		return $this->renderError($model->getError() ?: '更新失败');
	}

	/**
	 * 删除管理员
	 * @param int $companyId
	 * @return array|bool
	 */
	public function delete(int $companyId) {
		// 管理员详情
		$model = CompanyModel::detail($companyId);
		if (!$model->setDelete()) {
			return $this->renderError($model->getError() ?: '删除失败');
		}
		return $this->renderSuccess('删除成功');
	}
	public function stop(int $companyId) {
		// 管理员详情
		$model = CompanyModel::detail($companyId);
		if (!$model->stop()) {
			return $this->renderError($model->getError() ?: '操作失败');
		}
		return $this->renderSuccess('操作成功');
	}

}
